<style lang="scss" scoped>
  .form {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .el-form-item {
      width: 220px;
    }
  }
</style>
<template>
  <el-dialog :title="title" :visible.sync="addDialogVisible" width="35%">
    <div class="ui-box leave_dialog">
      <el-form :model="permsItem" label-width="80px" :rules="formRule" ref="formPerms" class="form">
        <el-form-item label="名称" prop="name">
          <el-input v-model="permsItem.name" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="描述" prop="description">
          <el-input v-model="permsItem.description" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="权限标识" prop="perms">
          <el-input v-model="permsItem.perms" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="url路径" prop="url">
          <el-input v-model="permsItem.url" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="父级路由">
          <el-select placeholder="父级路由" size="mini" v-model="permsItem.parentId" clearable>
            <el-option label="无" value="0"></el-option>
            <el-option :label="item.name" :value="item.permissionId" v-for="item in parentRoute"
                       :key="item.permissionId"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="层级" prop="type">
          <el-select placeholder="层级" size="mini"  v-model="permsItem.type" clearable>
            <el-option label="父路由" value="0"></el-option>
            <el-option label="子路由" value="1"></el-option>
          </el-select>
        </el-form-item>
<!--       <el-form-item label="层级" v-if="permsItem.parentId!==0">-->
<!--            <el-select placeholder="层级" size="mini"  v-model="permsItem.type" clearable>-->
<!--                <el-option label="父路由" :value="0"></el-option>-->
<!--                <el-option label="子路由" :value="1"></el-option>-->
<!--            </el-select>-->
<!--        </el-form-item>-->
        <el-form-item label="排序">
          <el-input v-model="permsItem.orderNum" size="mini"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="addDialogVisible = false" size="mini">取 消</el-button>
        <el-button type="primary" @click="submit" size="mini">确 定</el-button>
      </div>
    </div>
  </el-dialog>
</template>
<script>
  export default {
    name: 'addItem',
    props: {
      permsItem: {
        name: '',
        parentId: '',
        perms: '',
        orderNum: '',
        type:'',
        url: '',
        status: '',
        description: '',
        permissionId: '',
      }
    },
    data() {
      return {
        formRule: {
          name: [{required: true, message: '请输入名称', trigger: 'blur'}],
          url: [{required: true, message: '请输入路径', trigger: 'blur'}],
          description: [{required: true, message: '请输入描述', trigger: 'blur'}],
          perms: [{required: true, message: '请输入权限标识', trigger: 'blur'}],
        },
        addDialogVisible: false,
        title: '',
        parentRoute: [],
      }
    },
    mounted() {
      this.initParentRoute()
    },
    methods: {
      submit() {
        this.$refs['formPerms'].validate((val) => {
          if (val) {
            this.$emit('submit')
          }
        })
      },
      openWindow(value) {
        // console.log('title',value);
        this.title = value;
        this.addDialogVisible = true;
        this.permsItem.name = ''
      },
      initParentRoute() {
        this.parentRoute = this.$getGlobal.getItem('routers')
      }
    }
  }
</script>

